package edu.syr.iis.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import edu.syr.iis.web.model.AnnotationSession;
import edu.syr.iis.web.model.User;
import edu.syr.iis.web.util.Key;
import edu.syr.iis.web.util.SecurityManager;

public class SignOutController extends AbstractController {

	SecurityManager securityManager;
	String successView;
	
	
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		User user = (User) request.getSession().getAttribute(Key.USER);
		AnnotationSession annotationSession = securityManager.signOut(request);
		
		ModelAndView modelAndView = new ModelAndView(getSuccessView());
		modelAndView.addObject(Key.USER, user);
		modelAndView.addObject(Key.SESSION, annotationSession);
		return modelAndView;
	}


	public SecurityManager getSecurityManager() {
		return securityManager;
	}


	public void setSecurityManager(SecurityManager securityManager) {
		this.securityManager = securityManager;
	}

	public String getSuccessView() {
		return successView;
	}

	public void setSuccessView(String successView) {
		this.successView = successView;
	}

	
}
